package controlLayer;

import modelLayer.DVD;
import modelLayer.DVDContainer;
import modelLayer.Copy;

import java.util.Random;
/**
 * Write a description of class DVDCtr here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class DVDCtr
{
    // instance variables - replace the example below with your own
    private DVDContainer dvdCon;
    

    /**
     * Constructor for objects of class DVDCtr
     */
    public DVDCtr()
    {
        // Singleton initiation
        dvdCon = DVDContainer.getInstance();
    }

    
    // Create a DVD
    public void createDVD(String barcode, String title, String artist, String publicationDate, double price)
    {
        DVD dvd = new DVD(barcode, title, artist, publicationDate, price);
        dvdCon.addDVD(dvd);
        
        Random rnd = new Random();
        int randomNumber = 1000 + rnd.nextInt(9000);
        String serialNumber = "" + randomNumber;
        createCopy(dvd, serialNumber, null);
    }
    
    // Find a DVD
    public DVD findDVD(String barcode)
    {
        return dvdCon.getDVD(barcode);
    }
    
    // Update a DVD
    public void updateDVD(DVD dvd, String barcode, String title, String artist, String publicationDate, double price)
    {
        dvd.setBarcode(barcode);
        dvd.setTitle(title);
        dvd.setArtist(artist);
        dvd.setPublicationDate(publicationDate);
        dvd.setPrice(price);
    }    
    
    // Delete a DVD
    public void deleteDVD(DVD dvd) 
    {
        dvdCon.deleteDVD(dvd);
    }
    
    
    // Create a copy
    public void createCopy(DVD dvd,String serialNumber,String purchaseDate)
    {
        Copy newCopy = new Copy(serialNumber,purchaseDate);
        dvd.addCopy(newCopy);
    }
    
    // Find a copy
    public Copy findCopy(DVD dvd, String serialNumber)
    {
        return dvd.findCopy(serialNumber);
    }
    
    // Update a copy
    public void updateCopy(DVD dvd, Copy copy, String serialNumber, String purchaseDate) 
    {
        dvd.updateCopy(copy,serialNumber,purchaseDate);
    }
    
    // Delete a copy
    public void deleteCopy(DVD dvd,Copy copy)
    {
        dvd.deleteCopy(copy);
    }
}
